package com.androidtv.pos.ui;

import android.os.Bundle;
import android.os.Message;
import android.view.Display;

import com.androidhelper.module.common.base.BaseActivity;
import com.androidhelper.module.common.utils.DifferentDislay;
import com.androidtv.pos.R;
import com.androidtv.pos.ui.fragment.MainFragment;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.ToastUtils;

import java.util.Timer;
import java.util.TimerTask;

import androidx.annotation.Nullable;
import me.yokeyword.fragmentation.anim.DefaultHorizontalAnimator;
import me.yokeyword.fragmentation.anim.FragmentAnimator;

public class MainActivity extends BaseActivity {
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_main;
    }

    private Display mCurrDisplay;
    private DifferentDislay mMediaPresentation;




    @Override
    protected void initView(Bundle savedInstanceState) {
        //获取屏幕的宽度（单位：px）
        int  screenWidth=  ScreenUtils.getScreenWidth();
        int  appScreenWidth=  ScreenUtils.getAppScreenWidth();
        int  screenHeight=  ScreenUtils.getScreenHeight();
        int  appScreenHeight=  ScreenUtils.getAppScreenHeight();



        // 获取密度   dpi
        float  screenDensity=  ScreenUtils.getScreenDensity();
        float screenDensityDpi= ScreenUtils.getScreenDensityDpi();

        //计算尺寸
       /* ToastUtils.showLong("宽度:"+screenWidth+"  "+appScreenWidth+
                "高度"+screenHeight+"  "+ appScreenHeight
                +"密度"+screenDensity+"  "+screenDensityDpi);
           LogUtils.e("宽度:"+screenWidth+"  "+appScreenWidth+
                "高度"+screenHeight+"  "+ appScreenHeight
                +"密度"+screenDensity+"  "+screenDensityDpi);*/
         // ActivityUtils.getScreenPixel(MainActivity.this);
        //宽度:1920  1920高度1080  1080  密度3.0  480.0     meizu
        // 宽度:2340  2135高度1080  1080密度2.75  440.0  小米    尺寸
        //点餐系统     宽(大) 1920      高(小)  1080     密度  160.0        尺寸 13.7寸
        // 点餐   分辨率  1920高 *1080 宽      13.7尺寸






        //双屏显示
       /* DisplayManager mDisplayManager;//屏幕管理类
        Display[] displays;//屏幕数组
        mDisplayManager = (DisplayManager)MainActivity.this.getSystemService(Context.DISPLAY_SERVICE);
        displays =mDisplayManager.getDisplays(); //得到显示器数组
        ToastUtils.showLong("显示器数目"+displays.length);
        if (displays.length >= 2) {
            mCurrDisplay = displays[1];

            mMediaPresentation = new DifferentDislay(MainActivity.this, mCurrDisplay);
            mMediaPresentation.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
            mMediaPresentation.show();
        }*/
//        DifferentDislay mPresentation =new DifferentDislay (getApplicationContext(),displays[1]);//displays[1]是副屏
//        mPresentation.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
//        mPresentation.show();


        MainFragment mainFragment=   findFragment(MainFragment.class);
            if (mainFragment== null) {
            loadRootFragment(R.id.fl_container, MainFragment.newInstance());
        }




    }

    @Override
    protected void loadData(@Nullable Bundle savedInstanceState) {

    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void initStatusBar() {

    }

    @Override
    public void handleMessage(Message msg) {

    }


    @Override
    public void onBackPressedSupport() {
        super.onBackPressedSupport();
        //再点一次退出程序
      //  doubleClickExit();

    }
    @Override
    public FragmentAnimator onCreateFragmentAnimator() {
        // 设置横向(和安卓4.x动画相同)
        return new DefaultHorizontalAnimator();
    }




    private static Boolean mIsExit = false;
    //再点一次退出程序
    private void doubleClickExit() {
        Timer exitTimer = null;
        if (!mIsExit) {
            mIsExit = true;
            ToastUtils.showShort(getString(R.string.exit_again));
            exitTimer = new Timer();
            exitTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    mIsExit = false;
                }
            }, 2000);
        } else {
            finish();
            System.exit(0);
        }
    }



}
